package com.yunxi.controller.basedata;

import com.yunxi.basedata.pojo.CompanyVO;
import com.yunxi.basedata.service.CompanyDubboService;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 公司信息 前端控制器
 * </p>
 *
 * @author
 * @since 2019-05-21
 */
@RestController
@RequestMapping("/admin/company")
@Api(tags = "pms:company", description = "公司信息接口")
public class CompanyController {
   private static final Logger logger = LoggerFactory.getLogger(CompanyController.class);

   @Autowired
   CompanyDubboService companyDubboService;

   @GetMapping("/page")
   @ApiOperation(value = "查询分页")
   public ApiResult page(CompanyVO companyVO, Integer pageNum, Integer pageSize) throws Exception {
      return ResponseUtil.ok(companyDubboService.findPageByVO(companyVO, pageNum, pageSize));
   }

   @GetMapping("/list")
   @ApiOperation(value = "查询")
   public ApiResult list(CompanyVO companyVO) throws Exception {
      return ResponseUtil.ok(companyDubboService.listByVO(companyVO));
   }

   @GetMapping("/load")
   @ApiOperation(value = "读取单个")
   public ApiResult load(String companyId, @CurrentUser LoginInfo loginInfo) throws Exception {
      return ResponseUtil.ok(companyDubboService.getById(companyId));
   }

   @PostMapping("/save")
   @ApiOperation(value = "保存信息")
   public ApiResult save(@RequestBody CompanyVO companyVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      companyDubboService.saveOrUpdate(companyVO);
      return ResponseUtil.ok("success");
   }

   @PostMapping("/del")
   @ApiOperation(value = "删除")
   public ApiResult del(@RequestBody List<CompanyVO> companyVOList) throws Exception {
      companyDubboService.removeByListVo(companyVOList);
      return ResponseUtil.ok("success");
   }

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(companyDubboService.findMapByList(params));
}*/
}
